package org.tof.hotel.dao;

import org.tof.hotel.dto.RoomDTO;
import org.tof.hotel.jdbc.JConnection;
import org.tof.hotel.jdbc.Pool;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.SQLException;

public class RoomDaoImpl {
    private Pool pool;

    public RoomDaoImpl() throws IOException, ClassNotFoundException {
        this.pool = new Pool();
    }

    public RoomDaoImpl(Pool pool) {
        this.pool = pool;
    }

    public int insert(RoomDTO dto) throws SQLException {
        JConnection jConn = pool.getConnection();

        PreparedStatement prepStat = jConn.prepareStatement(
                "INSERT INTO administrator " +
                "(beds, roomLevel) " +
                "VALUES (?,?);");
        prepStat.setInt(1,dto.getBeds());
        prepStat.setInt(2, dto.getRoomLevel().ordinal());
        int result = prepStat.executeUpdate();
        pool.releaseConnection(jConn);
        return result;
    }
}
